package freespiritsocial.io.user.ui.fragment.mine

import android.os.Bundle
import freespiritsocial.io.user.R
import freespiritsocial.io.user.base.BaseFragment
import freespiritsocial.io.user.databinding.FrgChangeEmailBinding
import freespiritsocial.io.user.ext.setTitle
import freespiritsocial.io.user.ext.validateEmailAddress
import freespiritsocial.io.user.handle.BackHandle
import freespiritsocial.io.user.viewmodel.ChangeEmailViewModel
import me.hgj.jetpackmvvm.ext.nav

/**
 * @description 重置email
 */
class ChangeEmailFrg: BaseFragment<ChangeEmailViewModel,FrgChangeEmailBinding>() {
    override fun layoutId(): Int = R.layout.frg_change_email

    override fun initView(savedInstanceState: Bundle?) = with(mDatabind) {
        viewModel = mViewModel
        click = Click()
        root.setTitle("Change Email")
    }

    inner class Click: BackHandle {

        fun submit() {
            val email = mViewModel.email.get()
            if (email.validateEmailAddress().not()) {
                mViewModel.toast.postValue("Please enter a valid email address.")
                return
            }
            eventViewModel.changeEmailEvent.postValue(email)
            nav().navigateUp()
        }

        override fun goBack() {
            nav().navigateUp()
        }
    }
}